<template>
    <div class="tab-list">
        <div
            class="tab-item"
            :class="{ active: activeIndex === index }"
            v-for="(item, index) in list"
            :key="index"
            @click="changeIndex(index)"
        >
            {{ item.name }}
            <div class="line"></div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'TabList',
    props: {
        list: {
            type: Array,
            default: () => {
                return [];
            },
        },
        activeIndex: {
            type: Number,
            default: () => {
                return 0;
            },
        },
    },
    methods: {
        changeIndex(index) {
            this.$emit('change', index);
        },
    },
};
</script>

<style lang="scss" scoped>
.tab-list {
    padding: 28rpx 20rpx 0;
    width: 100%;
    box-sizing: border-box;
    @include flexBox(space-around, center);
    .tab-item {
        font-size: 28rpx;
        color: #2f2f2f;
        transition: 0.3s;
        @include flexBox(center, center, column);
        .line {
            width: 86rpx;
            height: 4rpx;
            transition: 0.3s;
            margin-top: 22rpx;
        }
        &.active {
            color: #5428ec;
            font-weight: 600;
            .line {
                background: #5428ec;
            }
        }
    }
}
</style>
